package 贪心;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @ClassName _435无重叠区间
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/12/25 21:12
 * Version 1.0
 **/
public class _435无重叠区间 {
    public int eraseOverlapIntervals(int[][] intervals) {
        int count = 0;
        Arrays.sort(intervals, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[0],o2[0]);
            }
        });
        for(int i = 1; i < intervals.length; i++){
            if(intervals[i][0] < intervals[i - 1][1]){
                intervals[i][1] = Math.min(intervals[i - 1][1],intervals[i][1]);
                count++;
            }
        }
        return count;
    }
}
